package com.siashan.unipay4j.wx;

import com.siashan.unipay4j.biz.PayBizConfiguration;
import com.siashan.unipay4j.biz.PayBizProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * 微信支付自动配置类
 *
 * @author siashan
 * @since v1.0.1
 **/
@Configuration
@EnableConfigurationProperties(WxPayProperties.class)
@Import(PayBizConfiguration.class)
public class WxPayAutoConfiguration {

    @Autowired
    private PayBizProperties payBizProperties;
    @Bean
    @ConditionalOnMissingBean
    public WxPayProperties wxPayProperties() {
        return new WxPayProperties();
    }


    @Bean
    @ConditionalOnMissingBean
    public WxPayFactoryProvider wxPayFactoryProvider(WxPayProperties wxPayProperties, WxPayFactory wxPayFactory) {
        return new WxPayFactoryProvider(wxPayProperties, wxPayFactory,payBizProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public WxPayFactory wxPayFactory() {
        return new WxPayFactory();
    }
}
